package game.seungha;

import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class Listener_SelectLevel implements OnItemSelectedListener
{
	Activity		mActivity;
	Vibrator		mVibrator;
	MediaPlayer 	mMediaPlayer;
	
	boolean		isFirst;
	
	Listener_SelectLevel(Activity activity)
	{
		Log.i("DBG", "[Listener_SelectLevel]Listener_SelectLevel"+" activity:"+activity);
		
		mActivity 		= activity;
		mMediaPlayer	= (MediaPlayer)((Activity_Main)mActivity).mMediaPlayer;
		isFirst			= true;
		
		if(mActivity.equals(game.seungha.Activity_Main.class))
		{
//			((Activity_Main)mActivity).mSpinner
		}
		
		
		mVibrator = (Vibrator) mActivity.getSystemService(Context.VIBRATOR_SERVICE);
	}
	
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)  
	{
		NGInfo		gameInfo;
		TextView	selectView;
		Spinner		levelSpinner;
		String		strLevel;
		
		boolean		isSelected = false;
		int			iVibrateTime = 0;
		
		levelSpinner = (Spinner) ((Activity_Main)mActivity).mSpinner; //findViewById(R.id.id_Spinner_Level);
		gameInfo 	 = NGInfo.getInstance();
		selectView 	 = (TextView) levelSpinner.getSelectedView();
		strLevel	 = (String) selectView.getText();

		Log.i("DBG", "[Listener_SelectLevel]onItemClick"+" selectView.getText():"+strLevel);
		
		if(isFirst)
		{
			Log.i("DBG", "[Listener_SelectLevel] [onItemClick] isFirst TRUE");
			
			isFirst = false;
			return;
		}
		
		if( strLevel.equalsIgnoreCase(mActivity.getString(R.string.str_com_level_easy)) )
		{
			gameInfo.setLevel(NG.LEVEL_EASY);
			isSelected = true;
			
			iVibrateTime = 100;
			mMediaPlayer = MediaPlayer.create(mActivity, R.raw.change_level);				
		}
		if( strLevel.equalsIgnoreCase(mActivity.getString(R.string.str_com_level_normal)) )
		{
			gameInfo.setLevel(NG.LEVEL_NORMAL);
			isSelected = true;
			
			iVibrateTime = 300;
			mMediaPlayer = MediaPlayer.create(mActivity, R.raw.change_level);				
		}
		if( strLevel.equalsIgnoreCase(mActivity.getString(R.string.str_com_level_hard)) )
		{
			gameInfo.setLevel(NG.LEVEL_HARD);
			isSelected = true;
			
			iVibrateTime = 500;
			mMediaPlayer = MediaPlayer.create(mActivity, R.raw.change_level);				
		}
		
		if( isSelected )
		{
			mMediaPlayer.start();
			//mMediaPlayer.setLooping(true);
			mVibrator.vibrate(iVibrateTime);
			Toast.makeText(mActivity, "Current Level [ "+strLevel+" ]", Toast.LENGTH_SHORT).show();
		}
		
		
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) 
	{
		// TODO Auto-generated method stub
		Log.i("DBG", "[Listener_SelectLevel] [onNothingSelected] arg0:"+arg0);
	}


}
